{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ec15473e",
   "metadata": {},
   "source": [
    "----\n",
    "- 记录人：vin\n",
    "- 时间：2021年12月6日\n",
    "- week14\n",
    "- 主要参考文档：[Python官方文档](https://www.python.org/)\n",
    "- [博客-函数](https://www.cnblogs.com/xuzhichao/p/11570285.html)\n",
    "\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49778b7c",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "- 1、函数的定义 ： def\n",
    "- 2、函数名的定义规则 -> 变量名一样的规则\n",
    "- 3、调用函数的方式\n",
    "- 4、参数\n",
    "    - 1、形式参数（定义参数）\n",
    "    - 2、实际参数（调用函数）\n",
    "    - 3、有多个参数时：\n",
    "  - 1、关键字参数\n",
    "  - 2、位置参数（调用函数时）——关键字参数要均放在末尾（多个不考虑顺序）\n",
    "  - 3、默认参数（定义函数时）——默认函数均放在末尾（多个不考虑顺序）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "852c146f",
   "metadata": {},
   "source": [
    "# 本周知识\n",
    "- 1、函数的返回值\n",
    "- 2、函数的参数类型\n",
    "- 3、模块与函数的关系\n",
    "- 4、定义一个模块，然后调用模块\n",
    "  - A、调用模块\n",
    "  - B、调用模块中的函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5df936b0",
   "metadata": {},
   "source": [
    "## 函数的返回值\n",
    "- 1.返回值的关键字 ： return \n",
    "- 2.在其他的编程语言中，一般 return 一定要写，不写会报错。但在python中，return 可以不写，return 默认为 None\n",
    "    - A、编程语言中的函数，一定有返回值\n",
    "    - B、返回值的结果是一个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "39e747de",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:14:05.444850Z",
     "start_time": "2021-12-06T02:14:05.435716Z"
    }
   },
   "outputs": [],
   "source": [
    "def get_formatted_name(first_name,last_name):\n",
    "    \"\"\"返回整洁的姓名\"\"\"\n",
    "    full_name = first_name + ' '+ last_name\n",
    "    # 函数的返回结果为 full_name\n",
    "    return full_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "898a473c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:14:06.431041Z",
     "start_time": "2021-12-06T02:14:06.418060Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'jekki_ vv'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_formatted_name('jekki_','vv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4058e391",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:14:07.334118Z",
     "start_time": "2021-12-06T02:14:07.311732Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jekki_ vv\n"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name('jekki_','vv'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a3d5e4ba",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:14:07.910505Z",
     "start_time": "2021-12-06T02:14:07.899523Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jekki zzang\n"
     ]
    }
   ],
   "source": [
    "idol = get_formatted_name('jekki','zzang') \n",
    "print(idol)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9faf9e2e",
   "metadata": {},
   "source": [
    "## 函数参数类型\n",
    "### 函数输入的参数\n",
    "- 1.函数是可以输入复杂的参数\n",
    "    - a、函数参数为列表\n",
    "    - b、函数参数为字典\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4b4f86be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:19:30.495440Z",
     "start_time": "2021-12-06T02:19:30.480161Z"
    }
   },
   "outputs": [],
   "source": [
    "def list_test(names):\n",
    "    '''函数输入一个列表'''\n",
    "    print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "42c13eab",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:20:01.443701Z",
     "start_time": "2021-12-06T02:20:01.436700Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['jekki', 'zzang', 'vv']\n"
     ]
    }
   ],
   "source": [
    "list_test(['jekki','zzang','vv'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "e22fc875",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:25:06.605186Z",
     "start_time": "2021-12-06T02:25:06.599203Z"
    }
   },
   "outputs": [],
   "source": [
    "def dict_test(request_header):\n",
    "    '''函数输入一个字典'''\n",
    "    print(request_header)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1127903c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:25:38.494088Z",
     "start_time": "2021-12-06T02:25:38.475069Z"
    }
   },
   "outputs": [],
   "source": [
    "## http://httpbin.org/get\n",
    "httpbin_get={\n",
    "  \"args\": {}, \n",
    "  \"headers\": {\n",
    "    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\", \n",
    "    \"Accept-Encoding\": \"gzip, deflate\", \n",
    "    \"Accept-Language\": \"zh-CN,zh;q=0.9\", \n",
    "    \"Host\": \"httpbin.org\", \n",
    "    \"Upgrade-Insecure-Requests\": \"1\", \n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36\", \n",
    "    \"X-Amzn-Trace-Id\": \"Root=1-61ad73bb-5850e4f720c06e25341253c0\"\n",
    "  }, \n",
    "  \"origin\": \"183.40.235.191\", \n",
    "  \"url\": \"http://httpbin.org/get\"\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "145a569e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:39:23.585464Z",
     "start_time": "2021-12-06T02:39:23.574449Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Host': 'httpbin.org', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36', 'X-Amzn-Trace-Id': 'Root=1-61ad73bb-5850e4f720c06e25341253c0'}\n"
     ]
    }
   ],
   "source": [
    "# 调用函数时，给一个字典做一个输入值\n",
    "dict_test(httpbin_get[\"headers\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8ea9a11",
   "metadata": {},
   "source": [
    "### 传递任意数量的参数\n",
    "- 1.  *args  传入多个参数，转化成元组\n",
    "    - *args 可以接受多个数据（单值）\n",
    "    - *args 将多个数据存在一个**元组**当中，实际上还是一个变量\n",
    "- 2.  **kwargs  把关键字参数，转化成字典\n",
    "    - **kwargs 可以接受多个数据（键值对）\n",
    "    - **kwargs 将多个数据（键值对）存放在一个字典中，实际上还是一个变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "e60bbfdb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:58:31.971474Z",
     "start_time": "2021-12-06T02:58:31.959471Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', 'mushroom', 'green peppers', 'extra cheese')"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 回顾元组的定义\n",
    "toppings = \"pizza\",\"mushroom\",\"green peppers\",\"extra cheese\"\n",
    "toppings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "52f0a5b6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:06:19.084246Z",
     "start_time": "2021-12-06T03:06:19.065709Z"
    }
   },
   "outputs": [],
   "source": [
    "## *args 实验\n",
    "def make_food(food,*toppings):  \n",
    "    \"\"\"打印顾客点的所有配料\"\"\"\n",
    "    return food,toppings\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "5c183229",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:58:33.247458Z",
     "start_time": "2021-12-06T02:58:33.230380Z"
    }
   },
   "outputs": [],
   "source": [
    "build_food = make_food(\"pizza\",\"mushroom\",\"green peppers\",\"extra cheese\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "a26b9738",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:58:33.966425Z",
     "start_time": "2021-12-06T02:58:33.942406Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', ('mushroom', 'green peppers', 'extra cheese'))"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "build_food"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "9f4b22ae",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:06:22.252730Z",
     "start_time": "2021-12-06T03:06:22.245574Z"
    }
   },
   "outputs": [],
   "source": [
    "## **kwargs 实验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "dc862c40",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:01:01.562235Z",
     "start_time": "2021-12-06T03:01:01.552237Z"
    }
   },
   "outputs": [],
   "source": [
    "def person(name,**info):\n",
    "    '''打印个人信息'''\n",
    "    return name,info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "eeb1c951",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:03:01.493618Z",
     "start_time": "2021-12-06T03:03:01.489632Z"
    }
   },
   "outputs": [],
   "source": [
    "build_person = person(\"G1\",age=40,job=\"idol\",address=\"韩国\",tel=\"我也想知道\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "26ed608d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:03:02.148457Z",
     "start_time": "2021-12-06T03:03:02.131456Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('G1', {'age': 40, 'job': 'idol', 'address': '韩国', 'tel': '我也想知道'})"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "build_person"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "371e447d",
   "metadata": {},
   "source": [
    "### 函数返回的结果\n",
    "- 函数可以返回任意类型的值，包括列表、字典和集合等较为复杂的数据结构。\n",
    "    - a、函数返回一个集合\n",
    "    - b、函数返回一个字典\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "8ed408ec",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:41:09.378011Z",
     "start_time": "2021-12-06T02:41:09.369507Z"
    }
   },
   "outputs": [],
   "source": [
    "## 函数返回一个集合\n",
    "def search4vowels(word):\n",
    "     \"\"\"Return a boolean based on any vowels found\"\"\"\n",
    "     vowels = set('aeiou')\n",
    "     found = vowels.intersection(set(word))\n",
    "     return found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "78ec447c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:41:09.989860Z",
     "start_time": "2021-12-06T02:41:09.984861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'i', 'a', 'e'}\n"
     ]
    }
   ],
   "source": [
    "word = search4vowels('jekki zzang')\n",
    "print(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a8ac62cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:43:08.380486Z",
     "start_time": "2021-12-06T02:43:08.361484Z"
    }
   },
   "outputs": [],
   "source": [
    "## 函数返回一个字典\n",
    "def build_person(name,age,job):\n",
    "     \"\"\"返回一个字典，其中包含有关一个人的信息\"\"\"\n",
    "     person = {'name':name,'age':age,'job':job}\n",
    "     return person"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "7e0c20b5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T02:44:08.563202Z",
     "start_time": "2021-12-06T02:44:08.554201Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'G1', 'age': '40', 'job': 'idol'}\n"
     ]
    }
   ],
   "source": [
    "person = build_person('G1','40','idol')\n",
    "print(person)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "099fe591",
   "metadata": {},
   "source": [
    "## 模块\n",
    "- 模块  用户不需要看底层代码\n",
    "- 调用模块的方法  ——必须先调用模块才可以使用\n",
    "    - 1.import moudle_name  直接调用整个模块，此时模块的所有函数处于备用状态，使用的方法为： moudle_name.func_name()\n",
    "    - 2.from  moudle_name import func_name   此时，仅调用模块的一个函数，只能使用这个模块的该函数，使用方法为： func_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "95d9bb67",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:54:44.984818Z",
     "start_time": "2021-12-06T03:54:44.964797Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i'}"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import study\n",
    "study.search4vowels('jekki zzang')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "07cd066e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T05:15:07.336247Z",
     "start_time": "2021-12-06T05:15:07.331245Z"
    }
   },
   "outputs": [],
   "source": [
    "from  study import news_链接   #该方法不需要再写模块的名字+.func_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "c3e7cf57",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:54:57.234622Z",
     "start_time": "2021-12-06T03:54:57.224621Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['https://www.nfu.edu.cn/xxyw/index.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index1.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index2.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index3.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index4.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index5.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index6.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index7.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index8.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index9.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index10.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index11.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index12.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index13.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index14.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index15.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index16.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index17.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index18.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index19.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index20.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index21.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index22.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index23.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index24.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index25.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index26.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index27.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index28.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index29.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index30.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index31.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index32.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index33.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index34.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index35.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index36.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index37.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index38.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index39.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index40.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index41.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index42.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index43.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index44.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index45.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index46.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index47.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index48.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index49.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index50.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index51.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index52.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index53.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index54.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index55.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index56.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index57.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index58.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index59.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index60.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index61.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index62.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index63.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index64.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index65.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index66.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index67.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index68.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index69.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index70.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index71.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index72.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index73.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index74.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index75.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index76.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index77.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index78.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index79.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index80.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index81.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index82.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index83.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index84.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index85.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index86.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index87.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index88.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index89.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index90.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index91.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index92.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index93.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index94.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index95.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index96.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index97.htm']"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news_链接('https://www.nfu.edu.cn/','xxyw',\"98\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "e5daa9a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:44:03.525083Z",
     "start_time": "2021-12-06T03:44:03.516065Z"
    }
   },
   "outputs": [],
   "source": [
    "## 抓取某个校园新闻的所有文本链接————广州南方学院\n",
    "\n",
    "url = \"https://www.nfu.edu.cn/\"\n",
    "def news_链接(url,新闻分类,page):\n",
    "    '''抓取学校新闻的所有链接'''\n",
    "    news_链接 = []\n",
    "    for i in range(0,int(page)):\n",
    "        if i == 0:\n",
    "            index_链接 = url + 新闻分类 + '/index.htm'\n",
    "            news_链接.append(index_链接)\n",
    "        else:\n",
    "            index_链接  = url + 新闻分类 + '/index' + str(i)+ '.htm'\n",
    "            news_链接.append(index_链接)\n",
    "    return news_链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "b3a3b546",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:46:37.429828Z",
     "start_time": "2021-12-06T03:46:37.418306Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['https://www.nfu.edu.cn/xxyw/index.htm', 'https://www.nfu.edu.cn/xxyw/index1.htm', 'https://www.nfu.edu.cn/xxyw/index2.htm', 'https://www.nfu.edu.cn/xxyw/index3.htm', 'https://www.nfu.edu.cn/xxyw/index4.htm', 'https://www.nfu.edu.cn/xxyw/index5.htm', 'https://www.nfu.edu.cn/xxyw/index6.htm', 'https://www.nfu.edu.cn/xxyw/index7.htm', 'https://www.nfu.edu.cn/xxyw/index8.htm', 'https://www.nfu.edu.cn/xxyw/index9.htm', 'https://www.nfu.edu.cn/xxyw/index10.htm', 'https://www.nfu.edu.cn/xxyw/index11.htm', 'https://www.nfu.edu.cn/xxyw/index12.htm', 'https://www.nfu.edu.cn/xxyw/index13.htm', 'https://www.nfu.edu.cn/xxyw/index14.htm', 'https://www.nfu.edu.cn/xxyw/index15.htm', 'https://www.nfu.edu.cn/xxyw/index16.htm', 'https://www.nfu.edu.cn/xxyw/index17.htm', 'https://www.nfu.edu.cn/xxyw/index18.htm', 'https://www.nfu.edu.cn/xxyw/index19.htm', 'https://www.nfu.edu.cn/xxyw/index20.htm', 'https://www.nfu.edu.cn/xxyw/index21.htm', 'https://www.nfu.edu.cn/xxyw/index22.htm', 'https://www.nfu.edu.cn/xxyw/index23.htm', 'https://www.nfu.edu.cn/xxyw/index24.htm', 'https://www.nfu.edu.cn/xxyw/index25.htm', 'https://www.nfu.edu.cn/xxyw/index26.htm', 'https://www.nfu.edu.cn/xxyw/index27.htm', 'https://www.nfu.edu.cn/xxyw/index28.htm', 'https://www.nfu.edu.cn/xxyw/index29.htm', 'https://www.nfu.edu.cn/xxyw/index30.htm', 'https://www.nfu.edu.cn/xxyw/index31.htm', 'https://www.nfu.edu.cn/xxyw/index32.htm', 'https://www.nfu.edu.cn/xxyw/index33.htm', 'https://www.nfu.edu.cn/xxyw/index34.htm', 'https://www.nfu.edu.cn/xxyw/index35.htm', 'https://www.nfu.edu.cn/xxyw/index36.htm', 'https://www.nfu.edu.cn/xxyw/index37.htm', 'https://www.nfu.edu.cn/xxyw/index38.htm', 'https://www.nfu.edu.cn/xxyw/index39.htm', 'https://www.nfu.edu.cn/xxyw/index40.htm', 'https://www.nfu.edu.cn/xxyw/index41.htm', 'https://www.nfu.edu.cn/xxyw/index42.htm', 'https://www.nfu.edu.cn/xxyw/index43.htm', 'https://www.nfu.edu.cn/xxyw/index44.htm', 'https://www.nfu.edu.cn/xxyw/index45.htm', 'https://www.nfu.edu.cn/xxyw/index46.htm', 'https://www.nfu.edu.cn/xxyw/index47.htm', 'https://www.nfu.edu.cn/xxyw/index48.htm', 'https://www.nfu.edu.cn/xxyw/index49.htm', 'https://www.nfu.edu.cn/xxyw/index50.htm', 'https://www.nfu.edu.cn/xxyw/index51.htm', 'https://www.nfu.edu.cn/xxyw/index52.htm', 'https://www.nfu.edu.cn/xxyw/index53.htm', 'https://www.nfu.edu.cn/xxyw/index54.htm', 'https://www.nfu.edu.cn/xxyw/index55.htm', 'https://www.nfu.edu.cn/xxyw/index56.htm', 'https://www.nfu.edu.cn/xxyw/index57.htm', 'https://www.nfu.edu.cn/xxyw/index58.htm', 'https://www.nfu.edu.cn/xxyw/index59.htm', 'https://www.nfu.edu.cn/xxyw/index60.htm', 'https://www.nfu.edu.cn/xxyw/index61.htm', 'https://www.nfu.edu.cn/xxyw/index62.htm', 'https://www.nfu.edu.cn/xxyw/index63.htm', 'https://www.nfu.edu.cn/xxyw/index64.htm', 'https://www.nfu.edu.cn/xxyw/index65.htm', 'https://www.nfu.edu.cn/xxyw/index66.htm', 'https://www.nfu.edu.cn/xxyw/index67.htm', 'https://www.nfu.edu.cn/xxyw/index68.htm', 'https://www.nfu.edu.cn/xxyw/index69.htm', 'https://www.nfu.edu.cn/xxyw/index70.htm', 'https://www.nfu.edu.cn/xxyw/index71.htm', 'https://www.nfu.edu.cn/xxyw/index72.htm', 'https://www.nfu.edu.cn/xxyw/index73.htm', 'https://www.nfu.edu.cn/xxyw/index74.htm', 'https://www.nfu.edu.cn/xxyw/index75.htm', 'https://www.nfu.edu.cn/xxyw/index76.htm', 'https://www.nfu.edu.cn/xxyw/index77.htm', 'https://www.nfu.edu.cn/xxyw/index78.htm', 'https://www.nfu.edu.cn/xxyw/index79.htm', 'https://www.nfu.edu.cn/xxyw/index80.htm', 'https://www.nfu.edu.cn/xxyw/index81.htm', 'https://www.nfu.edu.cn/xxyw/index82.htm', 'https://www.nfu.edu.cn/xxyw/index83.htm', 'https://www.nfu.edu.cn/xxyw/index84.htm', 'https://www.nfu.edu.cn/xxyw/index85.htm', 'https://www.nfu.edu.cn/xxyw/index86.htm', 'https://www.nfu.edu.cn/xxyw/index87.htm', 'https://www.nfu.edu.cn/xxyw/index88.htm', 'https://www.nfu.edu.cn/xxyw/index89.htm', 'https://www.nfu.edu.cn/xxyw/index90.htm', 'https://www.nfu.edu.cn/xxyw/index91.htm', 'https://www.nfu.edu.cn/xxyw/index92.htm', 'https://www.nfu.edu.cn/xxyw/index93.htm', 'https://www.nfu.edu.cn/xxyw/index94.htm', 'https://www.nfu.edu.cn/xxyw/index95.htm', 'https://www.nfu.edu.cn/xxyw/index96.htm', 'https://www.nfu.edu.cn/xxyw/index97.htm']\n"
     ]
    }
   ],
   "source": [
    "# 使用者只需要提供： url链接，学校分类的简称，页码\n",
    "学校要闻_result = news_链接('https://www.nfu.edu.cn/','xxyw',\"98\")\n",
    "print(学校要闻_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "0236b485",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-06T03:45:46.673553Z",
     "start_time": "2021-12-06T03:45:46.658539Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['https://www.nfu.edu.cn/xydt/index.htm', 'https://www.nfu.edu.cn/xydt/index1.htm', 'https://www.nfu.edu.cn/xydt/index2.htm', 'https://www.nfu.edu.cn/xydt/index3.htm', 'https://www.nfu.edu.cn/xydt/index4.htm', 'https://www.nfu.edu.cn/xydt/index5.htm', 'https://www.nfu.edu.cn/xydt/index6.htm', 'https://www.nfu.edu.cn/xydt/index7.htm', 'https://www.nfu.edu.cn/xydt/index8.htm', 'https://www.nfu.edu.cn/xydt/index9.htm', 'https://www.nfu.edu.cn/xydt/index10.htm', 'https://www.nfu.edu.cn/xydt/index11.htm', 'https://www.nfu.edu.cn/xydt/index12.htm', 'https://www.nfu.edu.cn/xydt/index13.htm', 'https://www.nfu.edu.cn/xydt/index14.htm', 'https://www.nfu.edu.cn/xydt/index15.htm', 'https://www.nfu.edu.cn/xydt/index16.htm', 'https://www.nfu.edu.cn/xydt/index17.htm', 'https://www.nfu.edu.cn/xydt/index18.htm', 'https://www.nfu.edu.cn/xydt/index19.htm', 'https://www.nfu.edu.cn/xydt/index20.htm', 'https://www.nfu.edu.cn/xydt/index21.htm', 'https://www.nfu.edu.cn/xydt/index22.htm', 'https://www.nfu.edu.cn/xydt/index23.htm', 'https://www.nfu.edu.cn/xydt/index24.htm', 'https://www.nfu.edu.cn/xydt/index25.htm', 'https://www.nfu.edu.cn/xydt/index26.htm', 'https://www.nfu.edu.cn/xydt/index27.htm', 'https://www.nfu.edu.cn/xydt/index28.htm', 'https://www.nfu.edu.cn/xydt/index29.htm', 'https://www.nfu.edu.cn/xydt/index30.htm', 'https://www.nfu.edu.cn/xydt/index31.htm', 'https://www.nfu.edu.cn/xydt/index32.htm', 'https://www.nfu.edu.cn/xydt/index33.htm', 'https://www.nfu.edu.cn/xydt/index34.htm', 'https://www.nfu.edu.cn/xydt/index35.htm', 'https://www.nfu.edu.cn/xydt/index36.htm', 'https://www.nfu.edu.cn/xydt/index37.htm', 'https://www.nfu.edu.cn/xydt/index38.htm', 'https://www.nfu.edu.cn/xydt/index39.htm', 'https://www.nfu.edu.cn/xydt/index40.htm', 'https://www.nfu.edu.cn/xydt/index41.htm', 'https://www.nfu.edu.cn/xydt/index42.htm', 'https://www.nfu.edu.cn/xydt/index43.htm', 'https://www.nfu.edu.cn/xydt/index44.htm', 'https://www.nfu.edu.cn/xydt/index45.htm', 'https://www.nfu.edu.cn/xydt/index46.htm', 'https://www.nfu.edu.cn/xydt/index47.htm', 'https://www.nfu.edu.cn/xydt/index48.htm', 'https://www.nfu.edu.cn/xydt/index49.htm', 'https://www.nfu.edu.cn/xydt/index50.htm', 'https://www.nfu.edu.cn/xydt/index51.htm', 'https://www.nfu.edu.cn/xydt/index52.htm', 'https://www.nfu.edu.cn/xydt/index53.htm', 'https://www.nfu.edu.cn/xydt/index54.htm', 'https://www.nfu.edu.cn/xydt/index55.htm', 'https://www.nfu.edu.cn/xydt/index56.htm', 'https://www.nfu.edu.cn/xydt/index57.htm', 'https://www.nfu.edu.cn/xydt/index58.htm', 'https://www.nfu.edu.cn/xydt/index59.htm', 'https://www.nfu.edu.cn/xydt/index60.htm', 'https://www.nfu.edu.cn/xydt/index61.htm', 'https://www.nfu.edu.cn/xydt/index62.htm', 'https://www.nfu.edu.cn/xydt/index63.htm', 'https://www.nfu.edu.cn/xydt/index64.htm', 'https://www.nfu.edu.cn/xydt/index65.htm', 'https://www.nfu.edu.cn/xydt/index66.htm', 'https://www.nfu.edu.cn/xydt/index67.htm', 'https://www.nfu.edu.cn/xydt/index68.htm', 'https://www.nfu.edu.cn/xydt/index69.htm', 'https://www.nfu.edu.cn/xydt/index70.htm', 'https://www.nfu.edu.cn/xydt/index71.htm', 'https://www.nfu.edu.cn/xydt/index72.htm', 'https://www.nfu.edu.cn/xydt/index73.htm', 'https://www.nfu.edu.cn/xydt/index74.htm', 'https://www.nfu.edu.cn/xydt/index75.htm', 'https://www.nfu.edu.cn/xydt/index76.htm', 'https://www.nfu.edu.cn/xydt/index77.htm', 'https://www.nfu.edu.cn/xydt/index78.htm', 'https://www.nfu.edu.cn/xydt/index79.htm', 'https://www.nfu.edu.cn/xydt/index80.htm', 'https://www.nfu.edu.cn/xydt/index81.htm', 'https://www.nfu.edu.cn/xydt/index82.htm', 'https://www.nfu.edu.cn/xydt/index83.htm', 'https://www.nfu.edu.cn/xydt/index84.htm', 'https://www.nfu.edu.cn/xydt/index85.htm', 'https://www.nfu.edu.cn/xydt/index86.htm', 'https://www.nfu.edu.cn/xydt/index87.htm', 'https://www.nfu.edu.cn/xydt/index88.htm', 'https://www.nfu.edu.cn/xydt/index89.htm', 'https://www.nfu.edu.cn/xydt/index90.htm', 'https://www.nfu.edu.cn/xydt/index91.htm', 'https://www.nfu.edu.cn/xydt/index92.htm', 'https://www.nfu.edu.cn/xydt/index93.htm', 'https://www.nfu.edu.cn/xydt/index94.htm', 'https://www.nfu.edu.cn/xydt/index95.htm']\n"
     ]
    }
   ],
   "source": [
    "校园动态_result = news_链接('https://www.nfu.edu.cn/','xydt',\"96\")\n",
    "print(校园动态_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fae53358",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
